const db = wx.cloud.database();
const app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {},


  onLoad: function (options) {
    var that = this;
    console.log(options);
 

    that.setData({
      area: options.area,
      geneal: options.agent,
      page: options.page
    })
    const phone = wx.getStorageSync('phone')
    if (phone) {
      wx.navigateTo({
        url: '../search/search/search',
      })
    }


  },

  getPhoneNumber(e) {
    var that = this;
    wx.cloud.callFunction({
      name: 'getMobile',
      data: {
        weRunData: wx.cloud.CloudID(e.detail.cloudID),
      }
    }).then(res => {
      that.setData({
        mobile: res.result,
      })
      var area = wx.getStorageSync('area')
      var agent = wx.getStorageSync('agent')
      var page = wx.getStorageSync('page')
      wx.request({
        url: 'https://tgadmin.sdwx.zgkfpt.cn/api/v1/collect_v3',
        method: 'POST',
        data: {
          activeId: 40,
          mobile: res.result,
          areaCode: area,
          agent: agent,
          pageId: page
        },
        success: res => {
          console.log(res);
        }
      })
      wx.setStorageSync('phone', res.result)
      console.log(res.result)
      wx.request({ //发送请求
        url: 'https://zg99.offcn.com/index/chaxun/register?actid=43723&callback=?', //接收url
        data: {
          phone: res.result,
          fenxiao: area,
          geneal: agent,
          isagree: true
        }, //接收参数
        success(res) {
          var jsonStr = res.data;
          jsonStr = jsonStr.replace("(", "");
          jsonStr = jsonStr.replace(")", "");
          if (typeof jsonStr != 'object') {
            jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
            var theJson = JSON.parse(jsonStr);
          }

          wx.navigateTo({
            url: '../search/search/search',
          })



        }

      })
    }).catch(err => {
      console.error(err);
    });
  },



  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    var that = this;
    var sence = wx.getStorageSync('scene')
    return {
      title: '2021山东公务员招录考试职位表',
      path: 'pages/index/index?scene=' + sence + '&by_qr=2'
    }
  },
  /**分享到朋友圈*/
  onShareTimeline: function () {
    var that = this;
    var sence = wx.getStorageSync('scene')
    return {
      title: '2021山东公务员招录考试职位表',
      path: 'pages/index/index?scene=' + sence + '&by_qr=2'
    }
  }
})